<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr> 
	  <td class="tahoma12G" style="padding-right: 5px;" >
			<?php
			$cart = $_SESSION['cart'];
			if(isset($_GET['action'])){
				$action = mysql_real_escape_string($_GET['action']);
				unset($_SESSION['cartConfirmCheckout']);
			}
			$itemId = 0;
			if(isset($_GET['id'])){
				$itemId = intval(mysql_real_escape_string($_GET['id']));
				$qItemCheck = "SELECT * from item where id = '$itemId'";
				$cqItemCheck= $db->sql_total($qItemCheck);
				if($cqItemCheck == 0){
					$action = "notvalid";
				}
				unset($_SESSION['cartConfirmCheckout']);
			}
			

			switch ($action) {
				case 'notvalid':
					break;
				case 'add':
					if ($cart) {
						$cart .= ','.$itemId;
					} else {
						$cart = $itemId;
					}
					break;
				case 'delete':
					if ($cart) {
						$items = explode(',',$cart);
						$newcart = '';
						foreach ($items as $item) {
							if ($itemId != $item) {
								if ($newcart != '') {
									$newcart .= ','.$item;
								} else {
									$newcart = $item;
								}
							}
						}
						$cart = $newcart;;
							
					}
					
					$cart = $newcart;
					break;

				case 'update':
				if ($cart) {
					//Delete product
					$box=$_POST['del'];
					$count = count($box);
					//echo 'ssssssss '.$count;
					if($count > 0){
						$newcart = null;
						$items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
						$itemTemp = $items;
						while (list ($key,$val) = @each ($box)) {
						    
							for($i=0; $i<=count($itemTemp); $i++){
							    
								//echo '<br /> Val :'.$val;
								//echo '<br />'.$i.' Item :'.$items[$i];
								if($val == $items[$i]){
									//echo '<br /> Remove  ';
									unset($items[$i]);
								}
							}
							
							
						} 
						$newcart = null;
							foreach ($items as $item) {
								if ($newcart != '') {
									$newcart .= ','.$item;
								} else {
									$newcart = $item;
								}
							}
						$cart = $newcart;
					}else{
						//Checking Update Quantity
						$newcart = null;
						foreach ($_POST as $key=>$value) {
							if (stristr($key,'qty')) {
								$id = str_replace('qty','',$key);
								$items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
								$newcart = '';
								
								foreach ($items as $item) {
									if ($id != $item) {
										if ($newcart != '') {
											$newcart .= ','.$item;
										} else {
											$newcart = $item;
										}
									}
								}
								for ($i=1;$i<=$value;$i++) {
									if ($newcart != '') {
										$newcart .= ','.$id;
									} else {
										$newcart = $id;
									}
								}
							}
						}
						if($newcart != null){
							$cart = $newcart;
							//echo 'hhh: '.$cart;
						}
					
					}
					break;
				}
				
			}
			$_SESSION['cart'] = $cart;
			?>
			
			<?php echo writeShoppingCart($lang);  ?>
	  </td>
	</tr>
	<tr> 
	  <td><img src="img/spec_blank.gif" width="10" height="5"></td>
	</tr>
	<tr> 
	  <td>  <?php if($_SESSION['cart'] != null || $_SESSION['cart'] !='' ){?>
			<a href="cart.php"><img src="img/btn_view.jpg" width="62" height="20" border="0"></a>
			 <?php }?>
	  </td>
	</tr>
</table>